package com.hspedu.newData.dmsxl.树.二叉树的遍历;

import com.hspedu.newData.dmsxl.ds.TreeNode;

/**
 * @Author: yh
 * @description: 
 * @CreateTime: 2025-05-13 
 * @Version: 1.0
 */

public class LC965单值二叉树 {

    boolean flag = true;

    int val = 0;

    public boolean isUnivalTree(TreeNode root) {

        val = root.val;
        return dfs(root);
    }

    public boolean dfs(TreeNode treeNode){
        if (treeNode == null){
            return flag;
        }

        if (val != treeNode.val){
            flag = false;
        }
        boolean left = dfs(treeNode.left);
        boolean right = dfs(treeNode.right);

        return left && right;
    }


}
